package com.xiaoning.sun.spring.mvc.controller;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.validation.BindingResult;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;

import com.xiaoning.sun.spring.mvc.model.RegisterForm;
import com.xiaoning.sun.spring.mvc.validator.LoginValidator;

@Controller
@RequestMapping(produces = { "application/json;charset=utf-8" }, value="/register")
public class RegisterController {
	
	private Logger logger = LoggerFactory.getLogger(LoginController.class);
	@Autowired
	LoginValidator loginValidator;
	
	@RequestMapping("/register")
	public ModelAndView authLogin(@ModelAttribute("registerForm") @Validated RegisterForm registerForm,BindingResult result, Model model){
		ModelAndView modelAndView = new ModelAndView();
		modelAndView.addObject("userName",registerForm.getUserName());
		if(result.hasErrors()){
			modelAndView.setViewName("login");
		}else{
			modelAndView.setViewName("success");
		}
		
		return modelAndView;
	}

}
